<?php
    namespace Home\Controller;
    use Think\Controller;
    class DanxiangchengjieluruController extends Controller {
    
    public function _initialize()
    {
        header("Access-Control-Allow-Origin: *");  

        header("Access-Control-Allow-Credentials: true"); 
      
        header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); //允许的请求类型
        
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); 

    }

    public function get_list()
    {
        $page = I("get.page");
        $limit = I("get.limit");

        $award_date = I('get.award_date');
        $dept_code  = I('get.dept_code');
        $type_id    = I('get.type_id');

        $where = " 1 = 1 ";

        if(!empty($award_date))
        {
            $award_date = strtotime($award_date);
            $where .= " and award_date = '$award_date'";
        }

        if(!empty($dept_code))
        {
            $where .= " and dept_code = '$dept_code'";
        }
        
        if(!empty($type_id))
        {
            $where .= " and type_id = '$type_id'";
        }
        
        $data = M("performance.input_singleaward")->WHERE($where)->limit(($page-1)*$limit,$limit)->select();
        for ($i=0; $i < count($data); $i++) 
        { 
            $info = $data[$i];
            $data[$i]['award_date'] = date('Y-m',$data[$i]['award_date']);
        }
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] = M("performance.input_singleaward")->WHERE($where)->count();
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }

    public function get_one()
    {
        $uuid = I("post.uuid");

        $info = M("performance.input_singleaward")->where("uuid = '$uuid'")->find();
        $info["award_date"] = date("Y-m",$info["award_date"]);

        $json["data"]   = $info;
        $json["code"]   = 0;
        $json["msg"]    = "";

        $this->ajaxReturn($json,"json");
    }

    public function save_one()
    {
        $data = I("post.");
        $uuid = $data["uuid"];
        unset($data["uuid"]);
        $data['award_date'] = strtotime($data['award_date']);

        $result = M("performance.input_singleaward")->where("uuid = '$uuid'")->save($data);
        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "修改成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "修改失败";
        }
 
        $this->ajaxReturn($json,"json");
    }

    public function add_one()
    {
        $data = I("post.");
        $uuid = uuid();
        

        $data['award_date'] = strtotime($data['award_date']);

        // var_dump($data);
        // die();


        $result = M("performance.input_singleaward")->add($data);
        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "添加成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "添加失败";
        }
 
        $this->ajaxReturn($json,"json");
    }

    public function get_guize_one()
    {
        $uuid = I("post.uuid");

        $info = M("performance.set_singleawarddict")->where("uuid = '$uuid'")->find();
        $json["data"]   = $info;
        $json["code"]   = 0;
        $json["msg"]    = "";

        $this->ajaxReturn($json,"json");
    }

    public function save_guize_one()
    {
        $data = I("post.");
        $uuid = $data["uuid"];
        unset($data["uuid"]);

        $result = M("performance.set_singleawarddict")->where("uuid = '$uuid'")->save($data);
        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "修改成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "修改失败";
        }
 
        $this->ajaxReturn($json,"json");
    }

    public function add_guize_one()
    {
        $data = I("post.");
        $uuid = uuid();
        

        $result = M("performance.set_singleawarddict")->add($data);
        if($result !== false)
        {
            $json["code"] = 0;
            $json["msg"] = "添加成功";
        }
        else
        {
            $json["code"] = -1;
            $json["msg"] = "添加失败";
        }
 
        $this->ajaxReturn($json,"json");
    }

    public function get_sys_dept_dict()
    {
        // echo 1;
        $data = M("comm.sys_dept_dict")->where("attr = 1")->select();
        for ($i=0; $i < count($data); $i++) 
        { 
            $info = $data[$i];
        }
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] =0 ;
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }

    public function get_singleawarddict()
    {
        // echo 1;
        $data = M("performance.set_singleawarddict")->select();
        for ($i=0; $i < count($data); $i++) 
        { 
            $info = $data[$i];
        }
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] =0 ;
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }

    public function get_singleawarddict_list()
    {
        $page = I("get.page");
        $limit = I("get.limit");


        $where = " 1 = 1 ";

        $data = M("performance.set_singleawarddict")->limit(($page-1)*$limit,$limit)->select();
        for ($i=0; $i < count($data); $i++) 
        { 
            $info = $data[$i];
        }
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] = M("performance.set_singleawarddict")->count();
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }

    public function get_item_name()
    {
       
        $where = " 1 = 1 ";

        $data = M("performance.set_singleawarddict")->select();
        
        $json["data"] = $data;
        $json["code"] = 0;
        $json["count"] = 0;
        $json["msg"] = "";
        
        $this->ajaxReturn($json,"json");
    }

}